import http from "@/service/request";

enum API {
  //     获取所有的城市
  GET_ALL_CITY = "/api/shop/city",
  // 新增一个地址
  ADD_NEW_ADRESS = "/api/shop/address",
  // 获取用户的地址
  GET_USER_ADDRESS = "/api/shop/address",
  // 设置为默认地址
  SET_DEFAULT_ADDRESS = "/api/shop/setDefault/",
  //更新地址信息
  UPDATE_ADDRESS = "/api/shop/address/",
  //删除一个地址
  DELETE_ADDRESS = "/api/shop/address/",
}

export function api_get_all_city() {
  return http({
    method: "GET",
    url: API.GET_ALL_CITY,
  });
}

export function api_add_or_update_address(data: any) {
  if (!!data.id) {
    return http({
      method: "PUT",
      url: API.UPDATE_ADDRESS + data.id,
      data,
    });
  } else {
    return http({
      method: "POST",
      url: API.ADD_NEW_ADRESS,
      data,
    });
  }
}

export function api_get_user_address() {
  return http({
    method: "GET",
    url: API.GET_USER_ADDRESS,
  });
}

export function api_set_default_address(id: number) {
  return http({
    method: "POST",
    url: API.SET_DEFAULT_ADDRESS + id,
  });
}

export function api_delete_address(id: number) {
  return http({
    method: "DELETE",
    url: API.DELETE_ADDRESS + id,
  });
}
